home *** CD-ROM | disk | FTP | other *** search
/ Pascal Super Library / Pascal Super Library (CW International)(1997).bin / MATH / MATH2 / POWTEN.PAS < prev    next >
Pascal/Delphi Source File  |  1985-05-17  |  2KB  |  61 lines

  1. (*--------------------------------------------------------------------------*)
  2. (*                   PowTen --- Calculate power of ten                      *)
  3. (*--------------------------------------------------------------------------*)
  4.  
  5. FUNCTION PowTen( Power : INTEGER ) : REAL;
  6.  
  7. (*--------------------------------------------------------------------------*)
  8. (*                                                                          *)
  9. (*     Function:  PowTen                                                    *)
  10. (*                                                                          *)
  11. (*     Purpose:   Calculates power of ten (integer powers only)             *)
  12. (*                                                                          *)
  13. (*     Calling Sequence:                                                    *)
  14. (*                                                                          *)
  15. (*        Powval := PowTen( Power: INTEGER ) : REAL;                        *)
  16. (*                                                                          *)
  17. (*           Power  --- power of ten desired (must be integer)              *)
  18. (*                                                                          *)
  19. (*           Powval --- resultant power of ten value                        *)
  20. (*                                                                          *)
  21. (*     Calls:  None                                                         *)
  22. (*                                                                          *)
  23. (*--------------------------------------------------------------------------*)
  24.  
  25. VAR
  26.    Temp   : REAL;
  27.    I      : INTEGER;
  28.    AbsPow : INTEGER;
  29.    X      : REAL;
  30.  
  31. BEGIN (* PowTen *)
  32.  
  33.    X     := 10.0;
  34.  
  35.    IF Power < 0 THEN
  36.       BEGIN
  37.          Power := -Power;
  38.          X     := 0.1;
  39.       END;
  40.  
  41.    Temp := 1.0;
  42.  
  43.    WHILE( Power > 0 ) DO
  44.       BEGIN
  45.  
  46.          WHILE ( NOT ODD( Power ) ) DO
  47.             BEGIN
  48.                Power := Power DIV 2;
  49.                X     := X * X;
  50.             END;
  51.  
  52.          Power := Power - 1;
  53.          Temp  := Temp  * X;
  54.  
  55.       END;
  56.  
  57.    PowTen := Temp;
  58.  
  59. END   (* PowTen *);
  60.  
  61.